package apps.softtech.Utility;

import java.util.ArrayList;
import java.util.List;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONObject;

import android.util.Log;

public class RequestDataFromServer {
    
   /**
    * get category child
    * @return string
    */
    public String requestCategoryChildList(int idCategoryParent){
   	 HttpRequest mHttpRequest = new HttpRequest();
		String url = ApplicationConstants.BASE_URL + "category/get_category_by_parent_id/";
		List<NameValuePair> params = new ArrayList<NameValuePair>();
		
		JSONObject json = new JSONObject();
		try{
			json.put("st_GcmId", ApplicationConstants.RED_ID);
			json.put("st_ParentCategoryId", idCategoryParent);
		}catch(Exception e){}
		params.add(new BasicNameValuePair("data", json.toString()));
		return mHttpRequest.makeServiceCall(url, HttpRequest.POST, params);
    }
    /**
     * get product list 
     * @return string
     */
     public String requestProductsList(int idCategory){
     	HttpRequest mHttpRequest = new HttpRequest();
 		String url =ApplicationConstants.BASE_URL +"product/get_product_by_category_id";
// 		"http://192.168.1.22/fastmarket/index.php/"
 		List<NameValuePair> params = new ArrayList<NameValuePair>();
 		
 		JSONObject json = new JSONObject();
 		try{
 			json.put("st_GcmId", ApplicationConstants.RED_ID);
 			json.put("st_CategoryId", idCategory);
 		}catch(Exception e){}
 		params.add(new BasicNameValuePair("data", json.toString()));
 		Log.v("",""+url+":\n"+params);
 		return mHttpRequest.makeServiceCall(url, HttpRequest.POST, params);//
     }
     /**
      * get product by name 
      * @return string
      */
      public String requestProductsByName(String NameProduct){
      	HttpRequest mHttpRequest = new HttpRequest();
  		String url =ApplicationConstants.BASE_URL +"product/get_product_by_name";
//  		"http://192.168.1.22/fastmarket/index.php/"
  		List<NameValuePair> params = new ArrayList<NameValuePair>();
  		
  		JSONObject json = new JSONObject();
  		try{
  			json.put("st_GcmId", ApplicationConstants.RED_ID);
  			json.put("st_ProductName", NameProduct);
  		}catch(Exception e){}
  		params.add(new BasicNameValuePair("data", json.toString()));
  		Log.v("",""+url+":\n"+params);
  		return mHttpRequest.makeServiceCall(url, HttpRequest.POST, params);//
      }
      /**
       * get User info
       * @return string
       */
       public String requestUserInfo(String UserName){
       	HttpRequest mHttpRequest = new HttpRequest();
   		String url =ApplicationConstants.BASE_URL +"users/get_user_infor_by_username";
   		List<NameValuePair> params = new ArrayList<NameValuePair>();
   		
   		JSONObject json = new JSONObject();
   		try{
   			json.put("st_GcmId", ApplicationConstants.RED_ID);
   			json.put("st_UserName", UserName);
   		}catch(Exception e){}
   		params.add(new BasicNameValuePair("data", json.toString()));
   		Log.v("",""+url+":\n"+params);
   		return mHttpRequest.makeServiceCall(url, HttpRequest.POST, params);//
       }
       
       /**
        * get my product
        * @return string
        */
        public String requestMyProductd(int id){
        	HttpRequest mHttpRequest = new HttpRequest();
    		String url =ApplicationConstants.BASE_URL +"product/get_product_by_user_id";
    		List<NameValuePair> params = new ArrayList<NameValuePair>();
    		
    		JSONObject json = new JSONObject();
    		try{
    			json.put("st_GcmId", ApplicationConstants.RED_ID);
    			json.put("st_UserId", id);
    		}catch(Exception e){}
    		params.add(new BasicNameValuePair("data", json.toString()));
    		return mHttpRequest.makeServiceCall(url, HttpRequest.POST, params);//
        }
        /**
         * get following
         * @return string
         */
         public String requestMyProfileFollowing(int ToUserId){
         	HttpRequest mHttpRequest = new HttpRequest();
     		String url =ApplicationConstants.BASE_URL +"follow_user/get_user_follow_to";
     		List<NameValuePair> params = new ArrayList<NameValuePair>();
     		
     		JSONObject json = new JSONObject();
     		try{
     			json.put("st_GcmId", ApplicationConstants.RED_ID);
     			json.put("st_ToUserId", ToUserId);
     			json.put("st_GetNotification", 1);
     		}catch(Exception e){}
     		params.add(new BasicNameValuePair("data", json.toString()));
     		Log.v("",""+url+":\n"+params);
     		return mHttpRequest.makeServiceCall(url, HttpRequest.POST, params);//
         }
         /**
          * get following
          * @return string
          */
          public String requestMyProfileFollower(int FromUserId){
          	HttpRequest mHttpRequest = new HttpRequest();
      		String url =ApplicationConstants.BASE_URL +"follow_user/get_user_follow_from";
      		List<NameValuePair> params = new ArrayList<NameValuePair>();
      		
      		JSONObject json = new JSONObject();
      		try{
      			json.put("st_GcmId", ApplicationConstants.RED_ID);
      			json.put("st_FromUserId", FromUserId);
      			json.put("st_GetNotification", 1);
      		}catch(Exception e){}
      		params.add(new BasicNameValuePair("data", json.toString()));
      		Log.v("",""+url+":\n"+params);
      		return mHttpRequest.makeServiceCall(url, HttpRequest.POST, params);//
          }//
         /**
          * get User by id
          * @return string
          */
          public String requestUserInfoById(int UserID){
          	HttpRequest mHttpRequest = new HttpRequest();
      		String url =ApplicationConstants.BASE_URL +"users/get_user_infor";
      		List<NameValuePair> params = new ArrayList<NameValuePair>();
      		
      		JSONObject json = new JSONObject();
      		try{
      			json.put("st_GcmId", ApplicationConstants.RED_ID);
      			json.put("st_UserId", UserID);
      		}catch(Exception e){}
      		params.add(new BasicNameValuePair("data", json.toString()));
      		Log.v("",""+url+":\n"+params);
      		return mHttpRequest.makeServiceCall(url, HttpRequest.POST, params);//
          }
          /**
           * unfollow user
           */
          public String requestUnfollow(int FromId,int ToId){
            	HttpRequest mHttpRequest = new HttpRequest();
        		String url =ApplicationConstants.BASE_URL +"follow_user/unfollow_user";
        		List<NameValuePair> params = new ArrayList<NameValuePair>();
        		
        		JSONObject json = new JSONObject();
        		try{
        			json.put("st_GcmId", ApplicationConstants.RED_ID);
//        			json.put("st_FromUserId", FromId);
        			json.put("st_ToUserId", ToId);
        		}catch(Exception e){}
        		params.add(new BasicNameValuePair("data", json.toString()));
        		Log.v("",""+url+":\n"+params);
        		return mHttpRequest.makeServiceCall(url, HttpRequest.POST, params);//
            }
          /**
           * follow User
           */
          public String requestFollowUser(int FromId,int ToId){
            	HttpRequest mHttpRequest = new HttpRequest();
        		String url =ApplicationConstants.BASE_URL +"follow_user/register_follow_user";
        		List<NameValuePair> params = new ArrayList<NameValuePair>();
        		
        		JSONObject json = new JSONObject();
        		try{
        			json.put("st_GcmId", ApplicationConstants.RED_ID);
        			json.put("st_FromUserId", FromId);
        			json.put("st_ToUserId", ToId);
        		}catch(Exception e){}
        		params.add(new BasicNameValuePair("data", json.toString()));
        		Log.v("",""+url+":\n"+params);
        		return mHttpRequest.makeServiceCall(url, HttpRequest.POST, params);//
            }
          /**
           * follow Product
           */
          public String requestFollowProduct(){
            	HttpRequest mHttpRequest = new HttpRequest();
        		String url =ApplicationConstants.BASE_URL +"follow_product/get_product_following";
        		List<NameValuePair> params = new ArrayList<NameValuePair>();
        		
        		JSONObject json = new JSONObject();
        		try{
        			json.put("st_GcmId", ApplicationConstants.RED_ID);
        		}catch(Exception e){}
        		params.add(new BasicNameValuePair("data", json.toString()));
        		Log.v("",""+url+":\n"+params);
        		return mHttpRequest.makeServiceCall(url, HttpRequest.POST, params);//
            }
          /**
           * Unfollow Product
           */
          public String requestUnFollowProduct(int UserId,int ProductId){
            	HttpRequest mHttpRequest = new HttpRequest();
        		String url =ApplicationConstants.BASE_URL +"follow_product/unfollow_product";
        		List<NameValuePair> params = new ArrayList<NameValuePair>();
        		
        		JSONObject json = new JSONObject();
        		try{
        			json.put("st_GcmId", ApplicationConstants.RED_ID);
        			json.put("st_UserId", UserId);
        			json.put("st_ProductId", 18);
        		}catch(Exception e){}
        		params.add(new BasicNameValuePair("data", json.toString()));
        		Log.v("",""+url+":\n"+params);
        		return mHttpRequest.makeServiceCall(url, HttpRequest.POST, params);//
            }
          /**
           * register follow Product
           */
          public String requestRegisterFollowProduct(int ProductId){
            	HttpRequest mHttpRequest = new HttpRequest();
        		String url =ApplicationConstants.BASE_URL +"follow_product/register_follow_product";
        		List<NameValuePair> params = new ArrayList<NameValuePair>();
        		
        		JSONObject json = new JSONObject();
        		try{
        			json.put("st_GcmId", ApplicationConstants.RED_ID);
        			json.put("st_ProductId", ProductId);
        		}catch(Exception e){}
        		params.add(new BasicNameValuePair("data", json.toString()));
        		Log.v("",""+url+":\n"+params);
        		return mHttpRequest.makeServiceCall(url, HttpRequest.POST, params);//
            }
          /**
           * get Product by id
           */
          public String requestGetProductById(int ProductId){
            	HttpRequest mHttpRequest = new HttpRequest();
        		String url =ApplicationConstants.BASE_URL +"product/get_product_by_id";
        		List<NameValuePair> params = new ArrayList<NameValuePair>();
        		
        		JSONObject json = new JSONObject();
        		try{
        			json.put("st_GcmId", ApplicationConstants.RED_ID);
        			json.put("st_ProductId", ProductId);
        		}catch(Exception e){}
        		params.add(new BasicNameValuePair("data", json.toString()));
        		return mHttpRequest.makeServiceCall(url, HttpRequest.POST, params);//
            }
          /**
           * reset password
           */
          public String requestResetPassword(String Email){
            	HttpRequest mHttpRequest = new HttpRequest();
        		String url =ApplicationConstants.BASE_URL +"users/reset_password";
        		List<NameValuePair> params = new ArrayList<NameValuePair>();
        		
        		JSONObject json = new JSONObject();
        		try{
        			json.put("st_GcmId", ApplicationConstants.RED_ID);
        			json.put("st_Email", Email);
        		}catch(Exception e){}
        		params.add(new BasicNameValuePair("data", json.toString()));
        		Log.v("",""+url+":\n"+params);
        		return mHttpRequest.makeServiceCall(url, HttpRequest.POST, params);//
            }
          /**
           * offer
           */
          public String requestOffer(int ProductId, float Price){
          	HttpRequest mHttpRequest = new HttpRequest();
      		String url =ApplicationConstants.BASE_URL +"offer/request_offer";
      		List<NameValuePair> params = new ArrayList<NameValuePair>();
      		
      		JSONObject json = new JSONObject();
      		try{
      			json.put("st_GcmId", ApplicationConstants.RED_ID);
      			json.put("st_ProductId", ProductId);
      			json.put("st_Price", Price);
      		}catch(Exception e){}
      		params.add(new BasicNameValuePair("data", json.toString()));
      		return mHttpRequest.makeServiceCall(url, HttpRequest.POST, params);//
          }
          /**
           *  remove offer
           */
          public String requestRemoveOffer(int idOffer){
          	HttpRequest mHttpRequest = new HttpRequest();
      		String url =ApplicationConstants.BASE_URL +"offer/remove_offer";
      		List<NameValuePair> params = new ArrayList<NameValuePair>();
      		
      		JSONObject json = new JSONObject();
      		try{
      			json.put("st_GcmId", ApplicationConstants.RED_ID);
      			json.put("st_OfferId", idOffer);
      		}catch(Exception e){}
      		params.add(new BasicNameValuePair("data", json.toString()));
      		return mHttpRequest.makeServiceCall(url, HttpRequest.POST, params);//
          }
          /**
           * get user info that offer to 1 product
           */
          public String requestUserOfferToProduct(int idProduct){
            	HttpRequest mHttpRequest = new HttpRequest();
        		String url =ApplicationConstants.BASE_URL +"offer/retrieve_infor_offering_by_product_id";
        		List<NameValuePair> params = new ArrayList<NameValuePair>();
        		
        		JSONObject json = new JSONObject();
        		try{
        			json.put("st_GcmId", ApplicationConstants.RED_ID);
        			json.put("st_ProductId", idProduct);
        		}catch(Exception e){}
        		params.add(new BasicNameValuePair("data", json.toString()));
        		Log.v("",""+url+":\n"+params);
        		return mHttpRequest.makeServiceCall(url, HttpRequest.POST, params);//
            }
    
}
